package ca.etsmtl.log210.vues;

import java.awt.Dimension;

import javax.swing.JPanel;

import ca.etsmtl.log210.modeles.Client;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;

public class PanneauClient extends JPanel
{
	//Le client pour lequel on veut afficher les informations
	Client clientActuel;
	private JTextField nomClient;
	private JTextField telephoneClient;
	private JTextField addresseClient;
	
	public PanneauClient(Client client)
	{
		clientActuel = client;
		//On utilise le meme size que l'emplacement ou on veut placer le panneau (hardcode)
		setSize(197,149);
		
		nomClient = new JTextField();
		nomClient.setHorizontalAlignment(SwingConstants.CENTER);
		nomClient.setEditable(false);
		nomClient.setColumns(10);
		
		telephoneClient = new JTextField();
		telephoneClient.setHorizontalAlignment(SwingConstants.CENTER);
		telephoneClient.setEditable(false);
		telephoneClient.setColumns(10);
		
		addresseClient = new JTextField();
		addresseClient.setHorizontalAlignment(SwingConstants.CENTER);
		addresseClient.setEditable(false);
		addresseClient.setColumns(10);
		
		JButton btnModifyYourInformation = new JButton("Modify your informations");
		btnModifyYourInformation.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) 
			{
				//TODO Modification du profil du client
			}
		});
		
		JLabel lblClientsInformations = new JLabel("Client's informations:");
		GroupLayout groupLayout = new GroupLayout(this);
		groupLayout.setHorizontalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup()
					.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
						.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
							.addContainerGap()
							.addGroup(groupLayout.createParallelGroup(Alignment.TRAILING)
								.addComponent(nomClient, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
								.addComponent(btnModifyYourInformation)
								.addComponent(telephoneClient, GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)))
						.addGroup(Alignment.LEADING, groupLayout.createSequentialGroup()
							.addGap(48)
							.addComponent(lblClientsInformations)))
					.addContainerGap())
				.addComponent(addresseClient, GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
		);
		groupLayout.setVerticalGroup(
			groupLayout.createParallelGroup(Alignment.LEADING)
				.addGroup(groupLayout.createSequentialGroup()
					.addGap(6)
					.addComponent(lblClientsInformations)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(nomClient, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(telephoneClient, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.UNRELATED)
					.addComponent(addresseClient, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
					.addPreferredGap(ComponentPlacement.RELATED)
					.addComponent(btnModifyYourInformation)
					.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
		);
		setLayout(groupLayout);
		
		nomClient.setText(clientActuel.getNom());
		telephoneClient.setText(clientActuel.getTelephone());
		addresseClient.setText(clientActuel.getAdresse().getAdresseGoogle());
		//TODO Ce panneau doit rentrer dans l'espace de login de GuiClient et doit afficher les infos du client
	}
}
